﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CommonUtils;
using TERP.WaterClient.Common;
using TERP.WaterClient.Entities.Booking;
using TERP.WaterClient.Entities.Tour;
using TERP.WaterClient.DbServices;
using TERP.WaterClient.Views;
using TERP.Utils;

namespace TERP.WaterClient.Views.Admin
{
    public partial class FrmImportExcel : FrmMdiBase
    {
        #region Properties
        private string strImportType = string.Empty;
        DataTable _dtblExl;
        //Const
        private const string Db_table_Import = "ImportType";
        private const string Field_Key = "key";
        private const string Field_Name = "Name";

        private const string Field_caption_Name = "Loại dữ liệu Import";

        //MSG
        private const string MSG_FILE_PATH_INVALID = "Chưa chọn file dữ liệu để thực hiện Import";
        private const string MSG_IMPORT_TYPE_INVALID = "Chưa chọn loại dữ liệu thực hiện Import";


        //
      

        #endregion

        #region Method

        void LoadImportType()
        {
            lukImportType.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo(Field_Key, 20, Field_Key));
            lukImportType.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo(Field_Name, 20, Field_caption_Name));

            DataTable dtImportType = new DataTable(Db_table_Import);
            dtImportType.Columns.Add(new DataColumn(Field_Key, typeof(System.String)));
            dtImportType.Columns.Add(new DataColumn(Field_Name, typeof(System.String)));

            ////Customer
            //DataRow dr = dtImportType.NewRow();
            //dr[Field_Key] = ImportExcel_Type.ImportExcel_Customer_Value;
            //dr[Field_Name] = ImportExcel_Type.ImportExcel_Customer_Caption;
            //dtImportType.Rows.Add(dr);

            ////Service
            //DataRow drSv = dtImportType.NewRow();
            //drSv[Field_Key] = ImportExcel_Type.ImportExcel_Service_Value;
            //drSv[Field_Name] = ImportExcel_Type.ImportExcel_Service_Caption;
            //dtImportType.Rows.Add(drSv);

            ////Part
            //DataRow drPart = dtImportType.NewRow();
            //drPart[Field_Key] = ImportExcel_Type.ImportExcel_Part_Value;
            //drPart[Field_Name] = ImportExcel_Type.ImportExcel_Part_Caption;
            //dtImportType.Rows.Add(drPart);

            ////Virtual Stock-in
            //DataRow drStockIn = dtImportType.NewRow();
            //drStockIn[Field_Key] = ImportExcel_Type.ImportExcel_StockIn_Value;
            //drStockIn[Field_Name] = ImportExcel_Type.ImportExcel_StockIn_Caption;
            //dtImportType.Rows.Add(drStockIn);

            lukImportType.Properties.DataSource = dtImportType;
            lukImportType.Properties.ValueMember = Field_Key;
            lukImportType.Properties.DisplayMember = Field_Name;

            lukImportType.Properties.Columns[Field_Key].Visible = false;
        }

        bool Check_filePath()
        {
            if (StringUtils.IsEmpty(strImportType))
            {
                Util.ShowWarningMsgBox(MSG_IMPORT_TYPE_INVALID);
                lukImportType.Focus();
                return false;
            }
            if (StringUtils.IsEmpty(txtBrowse.Text))
            {
                Util.ShowWarningMsgBox(MSG_FILE_PATH_INVALID);
                txtBrowse.Focus();
                return false;
            }
            return true;
        }


        #endregion

        #region Event
        

        public FrmImportExcel()
        {
            InitializeComponent();
        }
        
        private void btnImport_Click_1(object sender, EventArgs e)
        {
			strImportType = DbTable.Tbl_CustomerSupplier;
            try
            {
                //if (!Check_filePath()) return;

                Util.ShowMessageBox(InfoMessage.MSG_SAVE_SUCCESSFUL);
            }
            catch (Exception ex)
            {
                Util.ShowExceptionBox(ex);
                return;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FrmImportExcel_Load(object sender, EventArgs e)
        {
            LoadImportType();

            //checkedListBoxControl1.SelectionMode = SelectionMode.One;
        }

        private void lukImportType_EditValueChanged(object sender, EventArgs e)
        {
            strImportType = lukImportType.GetColumnValue(Field_Key).ToString();
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.Filter = Nonsense.FILTER_EXCEL_DIALOG;
                dlg.Multiselect = false;
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        txtBrowse.Text = dlg.FileName;


                        //
                        //TERP.HTCServiceClient.Common.ExcelImport _excelImport = new TERP.HTCServiceClient.Common.ExcelImport();
                        //_excelImport.GetSheetNames();
                    }
                    catch (Exception ex)
                    {
                        Util.ShowErrorMsgBox(ex.Message);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                Util.ShowErrorMsgBox(ex.Message);
            }
        }

        #endregion
    }
}
